<?php
defined ( 'BASEPATH' ) or exit ( 'No direct script access allowed' );
class Login extends CI_Controller {
	public function __construct() {
		parent::__construct ();
	}
	
	/**
	 * 登陆页显示
	 */
	public function index() {
		// 销毁上次登录可能存在的session
		// session_destroy();
		$this->load->helper ( 'form' );
		
		$this->load->view ( 'mobile/login' );
	}
	
	/**
	 * 信息提交
	 */
	public function info_post() {
		if (empty ( $_POST ['user_account'] ) or empty ( $_POST ['pwd'] )) {
			
			exit ( $this->common->alert_msg_goback ( '请输入用户名或密码' ) );
		}
		
		$this->load->model ( 'user_model' );
		$user = $this->user_model->check_user ( $_POST ['user_account'], md5 ( $_POST ['pwd'] ) );

		// 用户是否存在
		if (! empty ( $user )) {
			
			// session只保存id
			$_SESSION ['mobile'] ['id'] = $user ['id']; // $user;
            $_SESSION ['user']['id'] = $user ['id'];
		//	exit ( $this->common->alert_msg_url ( '欢迎登陆', site_url ( 'mobile/index' ) ) );
			header("location:".site_url ( 'mobile/index' ));
		} else {
			exit ( $this->common->alert_msg_goback ( '用户名或密码错误' ) );
		}
	}
	
	/**
	 * 退出登录
	 */
	public function logout() {
		session_destroy ();
		exit ( $this->common->alert_msg_url ( '退出成功', site_url ( 'mobile/login' ) ) );
	}
}
?>